package work.MrSun.xyq.controller;

/**
 * @Author MrSun
 * @Date 2023/4/16 19:14
 */

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import work.MrSun.xyq.model.XyqMessage;
import work.MrSun.xyq.service.XyqMessageDetailService;

/**
 * 分享实现层
 */
@RestController
public class ShareCountController {
    @Autowired
    private XyqMessageDetailService xyqMessageDetailService;

    /**
     * 增加分享方法 统计分享的次数
     *
     * @param messageId
     * @return
     */
    @PostMapping("/share/addShareCount/{messageId}")
    public Integer addShareCount(@PathVariable Integer messageId) {
        //通过id获取到分享信息
        XyqMessage message = xyqMessageDetailService.getById(messageId);
        XyqMessage xyqMessage = new XyqMessage();
        xyqMessage.setMessageId(messageId);
        xyqMessage.setMessageShare(message.getMessageShare() + 1);
        //新指定ID的分享信息对象，并返回分享次数。
        xyqMessageDetailService.update(xyqMessage);
        return message.getMessageShare();
    }

}
